package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.puti.common.core.domain.R;
import com.puti.doctor.domain.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;
import com.puti.doctor.domain.PatientHealth;
import com.puti.doctor.service.IPatientHealthService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 患者-健康档案 患者-健康档案Controller
 * 
 * @author puti
 * @date 2021-04-22
 */
@CrossOrigin
@RestController
@RequestMapping("/health")
public class PatientHealthController extends BaseController
{
    @Autowired
    private IPatientHealthService patientHealthService;

    /**
     * 查询患者-健康档案 患者-健康档案列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PatientHealth patientHealth)
    {
        startPage();
        List<PatientHealth> list = patientHealthService.selectPatientHealthList(patientHealth);
        return getDataTable(list);
    }

    /**
     * 导出患者-健康档案 患者-健康档案列表
     */
    @Log(title = "患者-健康档案 患者-健康档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientHealth patientHealth) throws IOException
    {
        List<PatientHealth> list = patientHealthService.selectPatientHealthList(patientHealth);
        ExcelUtil<PatientHealth> util = new ExcelUtil<PatientHealth>(PatientHealth.class);
        util.exportExcel(response, list, "患者-健康档案 患者-健康档案数据");
    }

    /**
     * 接诊台-未接诊列表-健康档案：弹出显示该患者用户档案；
     */
    @GetMapping(value = "/{healthId}")
    public R getInfo(@PathVariable("healthId") Long healthId) {
        return R.ok(patientHealthService.selectPatientHealthById(healthId),"查询成功!");
    }
    //接诊台-已接诊列表-诊断报告：弹出诊断报告；
    @GetMapping(value = "/info/{healthId}")
    public R getHealth(@PathVariable("healthId") Long healthId, @RequestParam("recordId")Long recordId) {
        return R.ok(patientHealthService.selectHealth(healthId,recordId),"查询成功!");
    }
    /**
     * 新增患者-健康档案 患者-健康档案
     */
    @Log(title = "患者-健康档案 患者-健康档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatientHealth patientHealth)
    {
        return toAjax(patientHealthService.insertPatientHealth(patientHealth));
    }

    /**
     * 修改患者-健康档案 患者-健康档案
     */
    @Log(title = "患者-健康档案 患者-健康档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatientHealth patientHealth)
    {
        return toAjax(patientHealthService.updatePatientHealth(patientHealth));
    }

    /**
     * 删除患者-健康档案 患者-健康档案
     */
    @Log(title = "患者-健康档案 患者-健康档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{healthIds}")
    public AjaxResult remove(@PathVariable Long[] healthIds)
    {
        return toAjax(patientHealthService.deletePatientHealthByIds(healthIds));
    }
}
